package com.cseg674.dataentry.javaparser;
/*
 * RdfVariableList.java
 *
 * Created on February 26, 2008, 12:40 PM
 *
 */

/**
 *
 * @author Tian, Juan
 */
import java.util.LinkedList;

/**
 * RdfVariableList provides the list of variables in the RDF output.
 */
public class RdfVariableList {

    /**
	 * Contains the list of variables
	 */
    LinkedList<RdfVariable> list = new LinkedList<RdfVariable> ();

    /**
	 * Default Constructor: Creates a new instance of RdfVariableList
     */
    public RdfVariableList() {
    }

    /**
	 * returns the number of variables
	 *
	 * @return	the number of variables in the 'list' list
     */
    public int size() {
        return list.size();
    }

    /**
	 * removes the a variable
	 *
	 * @param i the index of the variable to be removed from the 'list' list
	 */
    public void remove(int i) {
        list.remove(i);
    }

    /**
	 * deletes the variables to the specified level
	 *
	 * @param	level the level upto which variables are to be removed
	 * @return	<code>true</code> if the variables were successfully removed to the specified level
	 */
     public boolean deleteVariables (int level) {
        for( int i=0; i< size(); i++)
        {
            while(i < size() && (get(i)).getLevel() >= level) {
                remove(i);
            }
        }
        return true;
    }

    /**
	 * gets the variable at the specified index
	 *
	 * @param	i the index of the variable in the 'list' list
	 * @return	variable at the specified index
	 */
    public RdfVariable get(int i) {
        return list.get(i);
    }

    /**
	 * deletes the specified variable
	 *
	 * @param	a the variable to be removed
	 * @return	<code>true</code> if the variable was successfully removed from the 'list' list
	 */
    public boolean remove(RdfVariable a) {
        return list.remove(a);
    }

	/**
	 * gets the variable at the specified level AND name
	 *
	 * @param	level the level of the variable
	 * @param	name the name of the variable
	 * @return	variable at the specified level and name
	 */
    public RdfVariable getVariable(int level, String name) {
        for(int j = level; j >= 0; j --) {
        	for( int i=0; i< size(); i++){
	            if(get(i).getLevel() >= j && get(i).getName().equals(name)) {
	            	return get(i);
	            }
        	}
        }
        return null;
    }

    /**
	 * adds the specified variable to the list of variables
	 *
	 * @param	a the variable to be added
	 * @return	<code>true</code> if the variable was successfully added to the 'list' list
	 */
    public boolean addVariable(RdfVariable a){
        return list.add(a);
    }
}
